/**
 * ElectronExchanger Server Header File
 * 
 * File:        socket_helper.h
 * Brief:       BRIEF
 * Author:      Chen Kangbing
 * Email:       ckblau@outlook.com
 * Modified:    2020/09/08 17:24:01
 *
 */


#ifndef SOCKET_HELPER_H
#define SOCKET_HELPER_H

#ifdef __cplusplus
extern "C" {
#endif 


#include <sys/socket.h>
#include <arpa/inet.h>


typedef struct {
    int socket_port;
    struct sockaddr_in socket_srvaddr;
    int socket_srvfd;
} ServerSocketTypeDef;

typedef struct {
    struct sockaddr_in socket_cliaddr;
    int socket_clifd;
    pthread_t thread_tid;
    char *down_buffer;
    char *down_data;
    int down_data_size;
    int down_header_size;
    char *up_data;
    int up_data_size;
} TransmissionTypeDef;


int init_socket_server(ServerSocketTypeDef *psrv);
TransmissionTypeDef *create_transmission();
int loop_listen(ServerSocketTypeDef *psrv, TransmissionTypeDef *ptrans);
int transmit_down(TransmissionTypeDef *ptrans);
int transmit_up(TransmissionTypeDef *ptrans);
void shutdown_transmission(TransmissionTypeDef *ptrans);
void destroy_transmission(TransmissionTypeDef *ptrans);
void deinit_socket_server(ServerSocketTypeDef *psrv);


#ifdef __cplusplus
}
#endif 

#endif
